/*
 * 未封装的部分全局函数
 */
/**
 * @param {String} message
 * @param {String} url
 * @param {String} line
 */
window.onerror = function(message, url, line){
	console.error(
		"[window.onerror]"
		+ "\nmessage=" + message
		+ "\nurl=" + url
		+ "\nline=" + line
	);
};
/*
if(window.addEventListener){  //!ie
	window.addEventListener("message", function(msg){
		eval("(" + msg.data + ")");
	}, false);
}
*/

(function(){

var ext = [
	[String.prototype, {
		capitalize: function(){
			return this.charAt(0).toUpperCase() + this.substr(1);
		}
	}],
	[Array.prototype, {
		/**
		 * Checks whether or not the specified object exists in the array.
		 * @param {Object} o The object to check for
		 * @param {Number} from (Optional) The index at which to begin the search
		 * @return {Number} The index of o in the array (or -1 if it is not found)
		 */
		indexOf: function(o, from){
			var len = this.length;
			from = from || 0;
			from += (from < 0) ? len: 0;
			for(; from < len; ++from){
				if(this[from] === o){
					return from;
				}
			}
			return - 1;
		},
		removeAt: function(i){
			this.splice(i, 1);
		},
		/**
		 * Removes the specified object from the array. If the object is not found nothing happens.
		 * @param {Object} o The object to remove
		 * @return {Array} this array
		 */
		remove: function(o){
			var n = this.indexOf(o);
			if(n != -1){
				this.splice(n, 1);
			}
			return this;
		},
		contains: function(o){
			return this.indexOf(o) !== -1;
		}
	}]
];
if(typeof HTMLElement != "undefined"){
	ext.push([HTMLElement.prototype, {
		/**
		 * 判断当前元素是不是某个元素的父元素
		 */
		contains: function(el){
			while(el != null && typeof el.tagName != "undefind"){  //通过循环对比来判断是不是el的父元素
				if(el == this){
					return true;
				}
				el = el.parentNode;
			}
			return false;
		}
	}]);
}
function applyFixed(arr){
	for(var i = 0, len = arr.length; i < len; i++){
		var a = arr[i];
		var p = a[0];
		var hash = a[1];
		for(var k in hash){
			if(!p[k]){
				p[k] = hash[k];
			}
		}
	}
}
applyFixed(ext);

})();

function $E(id){
	return typeof id == "string" ? document.getElementById(id) : id;
	//return typeof el == "object" ? el : document.getElementById(el);
}

/**
 * @deprecated
 */
function toArray(array, start, end){
	return Array.prototype.slice.call(array, start || 0, end || array.length);
}
/**
 * @deprecated
 */
function addClass(el, cls){
	el.className = el.className ? el.className + " " + cls : cls;
}
/**
 * @deprecated
 */
function removeClass(el, cls){
	var arr = el.className.replace(/ +/g, " ").split(" ");
	var sb = [];
	for(var i = 0, len = arr.length; i < len; i++){
		var a = arr[i];
		if(a != ""){
			if(a != cls){
				sb.push(a);
			}
		}
	}
	el.className = sb.join(" ");
}
/**
 * @deprecated
 */
function replaceClass(el, oldCls, newCls){
	var arr = el.className.replace(/ +/g, " ").split(" ");
	var sb = [];
	for(var i = 0, len = arr.length; i < len; i++){
		var a = arr[i];
		if(a != ""){
			sb.push(a != oldCls ? a : newCls);
		}
	}
	el.className = sb.join(" ");
}